package com.tgy.algorithm.base._递归;

/**
 * 从左往右的尝试模型1
 *
 * 规定1和A对应、2和B对应、3和C对应... 26 Z
 * 111
 * 那么一个数字字符串比如"111”就可以转化为"AAA"、"KA"和"AK
 * 给定一个只有数字字符组成的字符串str，返回有多少种转化结果
 */
public class _从左往右尝试 {

    public static int getCount(String content) {

        char[] chars = content.toCharArray();
        int count = doCount(chars, 0);
        return count;
    }

    public static int doCount(char[] chars,int loc) {
        if (loc >= chars.length) {
            return 1;
        }

        char aChar = chars[loc];
        if (aChar == '0') {
            return 0;
        }

        int count = 0;

        // 只取一位作为当前值
        count += doCount(chars,loc+1);

        // 取两位
        if (aChar == '1') {
            // 取两位
            if (loc+2 <= chars.length) {
                count += doCount(chars,loc+2);
            }
        }else if(aChar == '2') {
            int next = loc + 1;
            if (next < chars.length && chars[next] >= '0' && chars[next] <= '6') {
                count += doCount(chars,loc+2);
            }
        }

        return count;
    }

    public static void main(String[] args) {

//        int count = getCount("111");
        int count = getCount("226");
        System.out.println(count);

    }
}
